//观察者和被观察者
// 被观察者要存放在观察者中
function Observer(){
    this.state='不开心的';
    this.arr=[];
}
Observer.prototype.attach = function (s) {
    this.arr.push(s);
}
Observer.prototype.setState=function (newState) {
    this.state=newState;
    this.arr.forEach(s=>s.update(this.state));
}
function Subject(name,target) {
    this.name=name;
    this.target=target;
}
Subject.prototype.update=function (newState) {
    console.log(this.name+' 监控到 了宝贝的：'+newState);
}

let o = new Observer();
let s1= new Subject('我',o);
let s2 = new Subject('我媳妇',o);
o.attach(s1);
o.attach(s2);
o.setState('开心');
o.setState('我不开心了');